﻿<template>
  <a-drawer
    :title="title"
    width="90%"
    :visible="visible"
    :confirmLoading="loading"
    @close="
      () => {
        this.visible = false
      }
    "
  >
    <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
      <!-- <a-form-model-item label="备注" prop="Remark">
          <a-input v-model="entity.Remark" autocomplete="off" placeholder="备注" />
        </a-form-model-item> -->
      <!-- <a-form-model-item label="价格表主表ID" prop="MIdPriceList">
          <a-input v-model="entity.MIdPriceList" autocomplete="off" placeholder="所属价格主表编号" />
        </a-form-model-item>
        <a-form-model-item label="产品ID" prop="ProductId">
          <a-input v-model="entity.ProductId" autocomplete="off" placeholder="产品编号" />
        </a-form-model-item> -->
      <a-row>
        <a-col :span="8">
          <a-form-model-item label="产品名称" prop="cInvName">
            <a-input v-model="entity.cInvName" autocomplete="off" placeholder="产品名称" />
          </a-form-model-item>
        </a-col>

        <a-col :span="8">
          <a-form-model-item label="标准价格" prop="StandardPrice">
            <a-input v-model="entity.StandardPrice" autocomplete="off" placeholder="标准价格" />
          </a-form-model-item>
        </a-col>

        <a-col :span="8">
          <a-form-model-item label="最低折扣" prop="MinimumDiscount">
            <a-input v-model="entity.MinimumDiscount" autocomplete="off" placeholder="最低折扣" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="8">
          <a-form-model-item label="数量下限1" prop="NumLowerLimit1">
            <a-input v-model="entity.NumLowerLimit1" autocomplete="off" placeholder="数量下限1" />
          </a-form-model-item>
        </a-col>

        <a-col :span="8">
          <a-form-model-item label="下限价格1" prop="LowerLimitPrice1">
            <a-input v-model="entity.LowerLimitPrice1" autocomplete="off" placeholder="下限价格1" />
          </a-form-model-item>
        </a-col>

        <a-col :span="8">
          <a-form-model-item label="数量下限2" prop="NumLowerLimit2">
            <a-input v-model="entity.NumLowerLimit2" autocomplete="off" placeholder="数量下限2" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="8">
          <a-form-model-item label="下限价格2" prop="LowerLimitPrice2">
            <a-input v-model="entity.LowerLimitPrice2" autocomplete="off" placeholder="下限价格2" />
          </a-form-model-item>
        </a-col>

        <a-col :span="8">
          <a-form-model-item label="数量下限3" prop="NumLowerLimit3">
            <a-input v-model="entity.NumLowerLimit3" autocomplete="off" placeholder="数量下限3" />
          </a-form-model-item>
        </a-col>

        <a-col :span="8">
          <a-form-model-item label="下限价格3" prop="LowerLimitPrice3">
            <a-input v-model="entity.LowerLimitPrice3" autocomplete="off" placeholder="下限价格3" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="8">
          <a-form-model-item label="更新时间" prop="UpdateTime">
            <a-date-picker format="YYYY-MM-DD" style="width: 100%" v-model="entity.UpdateTime" />
            <!-- <a-input v-model="entity.UpdateTime" autocomplete="off" placeholder="更新时间" /> -->
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>

    <div
      :style="{
        position: 'absolute',
        right: 0,
        bottom: 0,
        width: '100%',
        borderTop: '1px solid #e9e9e9',
        padding: '10px 16px',
        background: '#fff',
        textAlign: 'right',
        zIndex: 1
      }"
    >
      <a-button @click="close">取消</a-button>&nbsp;
      <a-button type="primary" @click="handleSubmit">保存</a-button>
    </div>
  </a-drawer>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  methods: {
    //取消按钮
    close() {
      this.visible = false
      this.data = []
      this.entity = {}
    },
    init() {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(id, title) {
      this.init()
      this.title = title
      if (id) {
        this.loading = true
        this.$http.post('/QuotationManagement/Quot_PriceListDetails/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/QuotationManagement/Quot_PriceListDetails/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
